package org.dromara.Nyt7Claim.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.Nyt7Claim.domain.vo.Nyt7ClaimVo;
import org.dromara.Nyt7Claim.domain.bo.Nyt7ClaimBo;
import org.dromara.Nyt7Claim.service.INyt7ClaimService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 保险理赔
 *
 * @author yt
 * @date 2024-12-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/Nyt7Claim/Nyt7Claim")
public class Nyt7ClaimController extends BaseController {

    private final INyt7ClaimService nyt7ClaimService;

    /**
     * 查询保险理赔列表
     */
    @SaCheckPermission("Nyt7Claim:Nyt7Claim:list")
    @GetMapping("/list")
    public TableDataInfo<Nyt7ClaimVo> list(Nyt7ClaimBo bo, PageQuery pageQuery) {
        return nyt7ClaimService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出保险理赔列表
     */
    @SaCheckPermission("Nyt7Claim:Nyt7Claim:export")
    @Log(title = "保险理赔", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(Nyt7ClaimBo bo, HttpServletResponse response) {
        List<Nyt7ClaimVo> list = nyt7ClaimService.queryList(bo);
        ExcelUtil.exportExcel(list, "保险理赔", Nyt7ClaimVo.class, response);
    }

    /**
     * 获取保险理赔详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("Nyt7Claim:Nyt7Claim:query")
    @GetMapping("/{id}")
    public R<Nyt7ClaimVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(nyt7ClaimService.queryById(id));
    }

    /**
     * 新增保险理赔
     */
    @SaCheckPermission("Nyt7Claim:Nyt7Claim:add")
    @Log(title = "保险理赔", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody Nyt7ClaimBo bo) {
        return toAjax(nyt7ClaimService.insertByBo(bo));
    }

    /**
     * 修改保险理赔
     */
    @SaCheckPermission("Nyt7Claim:Nyt7Claim:edit")
    @Log(title = "保险理赔", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody Nyt7ClaimBo bo) {
        return toAjax(nyt7ClaimService.updateByBo(bo));
    }

    /**
     * 删除保险理赔
     *
     * @param ids 主键串
     */
    @SaCheckPermission("Nyt7Claim:Nyt7Claim:remove")
    @Log(title = "保险理赔", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(nyt7ClaimService.deleteWithValidByIds(List.of(ids), true));
    }
}
